﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using KPIS.GERP.Models.HRM;

namespace KPIS.GERP.Models.SYS
{
    [DataContract, Table("SysApprovalTaskDtl")]
    public class ApprovalTaskDtl
    {
        [DataMember, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual int ApprovalTaskDtlId { get; set; }
        [DataMember] public virtual int CreatedOnActionCount { get; set; }
        [DataMember] public virtual bool IsCancel { get; set; }
        [DataMember] public virtual decimal? AmountMin { get; set; }
        [DataMember] public virtual decimal? AmountMax { get; set; }
        [DataMember] public virtual string SystemRemarks { get; set; }
        [DataMember, ForeignKey("ApprovalTask")] public virtual int? ApprovalTaskId { get; set; }
        [DataMember, ForeignKey("ApprovePath")] public virtual int? AppPathId { get; set; }
        [DataMember] public virtual int? FromMessageId { get; set; }
        [DataMember] public virtual int? FromApprovalTaskDtlId { get; set; }
        [DataMember] public virtual bool IsApproveAble { get; set; }
        [DataMember] public virtual bool IsForwardable { get; set; }
        [DataMember] public virtual bool IsRejectable { get; set; }
        [DataMember] public virtual bool IsPendable { get; set; }
        [DataMember] public virtual bool IsSendBackable { get; set; }
        [DataMember] public virtual bool IsLockable { get; set; }
        [DataMember] public virtual bool IsTakebackAble { get; set; }
        
        // Condition
        [DataMember] public virtual ApproverType ApproverType { get; set; }

        // Data
        [DataMember, ForeignKey("Position")] public virtual int? PosId { get; set; }
        [DataMember, ForeignKey("ExecPosGroup")] public virtual int? ExecPosGroupId { get; set; }

        // Result
        [DataMember] public virtual ICollection<ApprovalTaskDtlEmployee> Employees { get; set; }
        
        // Command by
        [DataMember, ForeignKey("CommandByEmployee"),] public virtual int? CommandByEmpId { get; set; }
        [DataMember] public virtual Employee CommandByEmployee { get; set; }
        [DataMember] public virtual CommandAction? CommandAction { get; set; }

        [DataMember] public virtual ApprovalTask ApprovalTask { get; set; }
        [DataMember] public virtual ApprovalTaskStatus TaskStatusBefore { get; set; }
        [DataMember] public virtual ApprovalTaskStatus TaskStatusAfter { get; set; }
        [DataMember] public virtual int StepBefore { get; set; }
        [DataMember] public virtual int StepAfter { get; set; }

        [DataMember] public virtual ExecPosGroup ExecPosGroup { get; set; }
        [DataMember] public virtual Position Position { get; set; }
        [DataMember] public virtual ApprovePath ApprovePath { get; set; }
        [DataMember] public virtual int? CreatedBy { get; set; }
        [DataMember] public virtual DateTime? CreatedWhen { get; set; }
        [DataMember] public virtual int? UpdatedBy { get; set; }
        [DataMember] public virtual DateTime? UpdatedWhen { get; set; }

        public virtual string AddSystemRemarks(string remark = null)
        {
            SystemRemarks = (SystemRemarks ?? string.Empty) + (string.IsNullOrWhiteSpace(remark) ? string.Empty : ", " + remark);
            return SystemRemarks;
        }
    }
}